import { request } from "./index"

//*----------- 获取首页顶部banner轮播图列表 --------------------------

export interface BannerModel {
  pic: string
  targetId: number
  targetType: number
  titleColor: string
  typeTitle: string
  url?: string
  bannerId: string
}

type ReqBannerListResModle = { banners: BannerModel[] }

export const reqBannerList = () =>
  request<ReqBannerListResModle>({
    url: "/banner",
    params: { type: 2 },
  })

//*------------------获取推荐歌曲列表-------------------
export interface RecommedModel {
  id: number
  type: number
  name: string
  copywriter: string
  picUrl: string
  canDislike: boolean
  trackNumberUpdateTime: number
  playCount: number
  localPlayCount?: string
  trackCount: number
  highQuality: boolean
  alg: string
}

type ReqRecommedListResModle = { result: RecommedModel[] }

export const reqRecommedList = (limit: number = 15) =>
  request<ReqRecommedListResModle>({
    url: "/personalized",
    params: { limit: limit },
  })

//*----------------获取排行榜列表----------------------

export interface TracksModel {
  name: string
  id: number
  al: {
    id: number
    picUrl: string
  }
}

export interface PlaylistModel {
  id: number
  name: string
  tracks: TracksModel[]
}

type ReqRankListResModel = { playlist: PlaylistModel }

export const reqRankList = (idx: number) =>
  request<ReqRankListResModel>({
    url: "/top/list",
    params: { idx },
  })

//*---------------获取欧美新专速递------------------------

interface ArtistModel {
  followed: boolean
  name: string
  id: number
}

interface AlbumModel {
  blurPicUrl: string
  artists: ArtistModel[]
  name: string
  id: number
  size: number
}

export interface TopListModel {
  id: number
  album: AlbumModel
}

type ReqTopListResModel = {
  data: TopListModel[]
}

//! 如果需要将请求abort，就需要写成这样，设一个接口描述函数是为了代码提示带有abort字段
//! 给request里的this通过bind绑定为这个请求函数，在request中会把abort函数添加到this身上
interface ReqTopList {
  (): Promise<ReqTopListResModel>
  abort?: () => void
}

export const reqTopList: ReqTopList = () =>
  request.bind(reqTopList)({
    url: "/top/song",
    params: { type: 96 },
  })

// export function reqTopList() {
//   return
// }

